//
//  ImageShowViewController.m
//  XLPhotoBrowserDemo
//
//  Created by aron on 2017/4/4.
//  Copyright © 2017年 LiuShannoon. All rights reserved.
//

#import "ImageShowViewController.h"
#import "XLPhotoBrowser.h"

@interface ImageShowViewController ()<XLPhotoBrowserDelegate, XLPhotoBrowserDatasource>

@property(nonatomic ,assign)NSInteger index;
@property(nonatomic ,retain)NSArray *images;

/**
 * scrollView
 */
@property (nonatomic , strong) UIScrollView  *scrollView;

@end

@implementation ImageShowViewController

- (id)initWithImages:(NSArray *)data withIndex:(NSInteger)index {
    self = [super init];
    if (self) {
        self.images = data;
        _index = index;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 快速创建并进入浏览模式
    XLPhotoBrowser *browser = [XLPhotoBrowser showPhotoBrowserWithCurrentImageIndex:_index imageCount:self.images.count datasource:self];
    browser.delegate = self;
    browser.browserStyle = XLPhotoBrowserStyleSimple;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark    -   XLPhotoBrowserDatasource

/**
 *  返回指定位置图片的UIImageView,用于做图片浏览器弹出放大和消失回缩动画等
 *  如果没有实现这个方法,没有回缩动画,如果传过来的view不正确,可能会影响回缩动画效果
 *
 *  @param browser 浏览器
 *  @param index   位置索引
 *
 *  @return 展示图片的容器视图,如UIImageView等
 */
//- (UIView *)photoBrowser:(XLPhotoBrowser *)browser sourceImageViewForIndex:(NSInteger)index
//{
//    return self.scrollView.subviews[index];
//}

/**
 *  返回指定位置的高清图片URL
 *
 *  @param browser 浏览器
 *  @param index   位置索引
 *
 *  @return 返回高清大图索引
 */
- (NSURL *)photoBrowser:(XLPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index
{
    return [NSURL URLWithString:self.images[index]];
}

#pragma mark    -   XLPhotoBrowserDelegate

- (void)photoBrowser:(XLPhotoBrowser *)browser clickActionSheetIndex:(NSInteger)actionSheetindex currentImageIndex:(NSInteger)currentImageIndex
{
    // do something yourself
    switch (actionSheetindex) {
        case 1: // 保存
        {
            NSLog(@"点击了actionSheet索引是:%zd , 当前展示的图片索引是:%zd",actionSheetindex,currentImageIndex);
            [browser saveCurrentShowImage];
        }
            break;
        default:
        {
            NSLog(@"点击了actionSheet索引是:%zd , 当前展示的图片索引是:%zd",actionSheetindex,currentImageIndex);
        }
            break;
    }
}

- (void)photoBrowser:(XLPhotoBrowser *)browser didDismiss:(BOOL)dismiss {
    if (dismiss) {
        [self.navigationController popViewControllerAnimated:NO];
    }
}

@end
